﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;
using System.Data;
using Honestysoft.BaseObject;
using System.Drawing;
using Honestysoft.Workflow.BusinessFacade;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public partial class AuditTable_Edit : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                BindControl();
                Bind();
                BindWF();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            WFButtons1.AfterCall += new WorkFlow_Control_WFButtons.AfterCallEventHandler(WFButtons1_AfterCall);
            btnReceive.Click += new EventHandler(btnReceive_Click);
        }

        void btnReceive_Click(object sender, EventArgs e)
        {
            BindControl();
            Bind();
            BindWF();
        }

        void WFButtons1_AfterCall(Workflow.Model.WFReturn pWFReturn)
        {
            //如果被退回初始，那么没有作业表了，要关闭窗口并刷新父窗口
            if (pWFReturn.IsSuccess && pWFReturn.ToActTemplates != null && pWFReturn.ToActTemplates[0].ActType == ((int)Workflow.Model.WFEnumData.ActType.Start).ToString())
            {
                //虚拟数据，使页面有数据可绑定
                theTable = new Bu_AuditTable();
                theTable.SummaryAmount = new Bu_AuditTable_Amount();
                theTable.DocRecTime = DateTime.Now;
                theTable.TableType = "A";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "refreshParent", "alert('流程已被退回到初始，请重新派单！');window.opener.location.reload();window.close();", true);
            }
            else
            {
                BindControl();
                Bind();
                BindWF();
                Page.ClientScript.RegisterStartupScript(typeof(string), "refreshParent", "outputExcel();window.opener.location.reload()", true);
            }
        }

        protected string FormatRecDate(DateTime date)
        {
            string ret = string.Format("{0:yyyy年M月d日}（周", date);

            switch (date.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    ret += "一";
                    break;
                case DayOfWeek.Tuesday:
                    ret += "二";
                    break;
                case DayOfWeek.Wednesday:
                    ret += "三";
                    break;
                case DayOfWeek.Thursday:
                    ret += "四";
                    break;
                case DayOfWeek.Friday:
                    ret += "五";
                    break;
                case DayOfWeek.Saturday:
                    ret += "六";
                    break;
                case DayOfWeek.Sunday:
                    ret += "日";
                    break;
                default:
                    break;
            }
            ret += "）";
            return ret;
        }
        private DataTable dtYesNo = null;
        private void BindRadioList(RadioButtonList rbl)
        {
            rbl.DataSource = dtYesNo;
            rbl.DataTextField = "Text";
            rbl.DataValueField = "Value";
            rbl.DataBind();
            rbl.SelectedIndex = 0;
        }
        protected Bu_AuditTable theTable = null;

        /// <summary>
        /// 绑定控件
        /// </summary>
        private void BindControl()
        {
            dtYesNo = new DataTable();
            dtYesNo.Columns.Add("Text", typeof(string));
            dtYesNo.Columns.Add("Value", typeof(string));
            DataRow dr = dtYesNo.NewRow();
            dr["Text"] = "有  ";
            dr["Value"] = "1";
            dtYesNo.Rows.Add(dr);
            dr = dtYesNo.NewRow();
            dr["Text"] = "无";
            dr["Value"] = "0";
            dtYesNo.Rows.Add(dr);

            BindRadioList(rblPD1);
            BindRadioList(rblPD2);
            BindRadioList(rblPD3);
            BindRadioList(rblPD4);
            BindRadioList(rblPD5);
            BindRadioList(rblPD6);
            BindRadioList(rblPD7);
            BindRadioList(rblPD8);
            BindRadioList(rblPD9);
            BindRadioList(rblPD10);

            BindRadioList(rblZD1);
            BindRadioList(rblZD2);
            BindRadioList(rblZD3);
            BindRadioList(rblZD4);

            BindRadioList(rblCD1);
            BindRadioList(rblCD2);
            BindRadioList(rblCD3);
            BindRadioList(rblCD4);
            BindRadioList(rblCD5);
            BindRadioList(rblCD6);
            BindRadioList(rblCD7);
            BindRadioList(rblCD8);
            BindRadioList(rblCD9);

            SetOpinionReadOnly(true);
            SetAmountReadOnly(true);
            SetCDEnabled(false);
            SetPDEnabled(false);
            SetZDEnabled(false);

            btnReceive.Enabled = false;
            btnViewReceive.Enabled = false;
            btnSave.Enabled = false;
        }
        /// <summary>
        /// 绑定工作流控件
        /// </summary>
        private void BindWF()
        {
            WFButtons1.BillCode = ((int)EnumItem.WFBill.AuditTable).ToString();
            WFButtons1.EmployeeID = UserLoginer.LoginUser.ID;
            WFButtons1.BuDataID = Request.QueryString["ID"];
            WFButtons1.IsCallBackPage = true;
            WFButtons1.IsHiddenBtnStart = true;
            //如果已进入审核，则表示已签收，不能再收回
            if (theTable.BuStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString())
            {
                WFButtons1.IsHiddenBtnRecall = true;
            }
            WFButtons1.BindWFControl();
        }
        /// <summary>
        /// 设置金额单元格只读属性
        /// </summary>
        /// <param name="readOnly"></param>
        private void SetAmountReadOnly(bool readOnly)
        {
            numAmount_DocRec.ReadOnly = readOnly;
            numCurAmount.ReadOnly = readOnly;
            numTAmount_C_A.ReadOnly = readOnly;
            numAmount_C.ReadOnly = readOnly;
        }
        /// <summary>
        /// 设置意见单元格只读属性
        /// </summary>
        private void SetOpinionReadOnly(bool readOnly)
        {
            txtCD.ReadOnly = readOnly;
            txtCDOpinion.ReadOnly = readOnly;
            txtForCPriceOpinion.ReadOnly = readOnly;
            txtForLoanOpinion.ReadOnly = readOnly;
            txtForPlanOpinion.ReadOnly = readOnly;
            txtForPPriceOpinion.ReadOnly = readOnly;
            txtForProgress.ReadOnly = readOnly;
            txtForProgressOpinion.ReadOnly = readOnly;
            txtPD1.ReadOnly = readOnly;
            txtPD1Opinion.ReadOnly = readOnly;
            txtPD2.ReadOnly = readOnly;
            txtPD2Opinion.ReadOnly = readOnly;
            txtZDOpinion.ReadOnly = readOnly;
        }
        /// <summary>
        /// 设置项目资料完整性控件可见性
        /// </summary>
        /// <param name="visible"></param>
        private void SetPDVisible(bool visible)
        {
            rblPD1.Visible = visible;
            rblPD2.Visible = visible;
            rblPD3.Visible = visible;
            rblPD4.Visible = visible;
            rblPD5.Visible = visible;
            rblPD6.Visible = visible;
            rblPD7.Visible = visible;
            rblPD8.Visible = visible;
            rblPD9.Visible = visible;
            rblPD10.Visible = visible;
        }
        /// <summary>
        /// 设置项目资料完整性控件有效性
        /// </summary>
        /// <param name="enabled"></param>
        private void SetPDEnabled(bool enabled)
        {
            rblPD1.Enabled = enabled;
            rblPD2.Enabled = enabled;
            rblPD3.Enabled = enabled;
            rblPD4.Enabled = enabled;
            rblPD5.Enabled = enabled;
            rblPD6.Enabled = enabled;
            rblPD7.Enabled = enabled;
            rblPD8.Enabled = enabled;
            rblPD9.Enabled = enabled;
            rblPD10.Enabled = enabled;
        }
        /// <summary>
        /// 设置合同资料完整性控件有效性
        /// </summary>
        /// <param name="enabled"></param>
        private void SetCDEnabled(bool enabled)
        {
            rblCD1.Enabled = enabled;
            rblCD2.Enabled = enabled;
            rblCD3.Enabled = enabled;
            rblCD4.Enabled = enabled;
            rblCD5.Enabled = enabled;
            rblCD6.Enabled = enabled;
            rblCD7.Enabled = enabled;
            rblCD8.Enabled = enabled;
            rblCD9.Enabled = enabled;
        }
        /// <summary>
        /// 设置资本金资料完整性控件有效性
        /// </summary>
        /// <param name="enabled"></param>
        private void SetZDEnabled(bool enabled)
        {
            rblZD1.Enabled = enabled;
            rblZD2.Enabled = enabled;
            rblZD3.Enabled = enabled;
            rblZD4.Enabled = enabled;
        }

        protected int yearCount = 0;
        protected string yearString = "";

        bool isEnabled = false;

        protected string GetIsDisplay()
        {
            if (!isEnabled)
            {
                return "  style='display:none'";
            }
            return "";
        }
        protected string _BuStatus = "";
        protected string _SwfFilePath = "";
        protected string _Code = "";
        protected string _BatchNo = "";
        /// <summary>
        /// 绑定页面
        /// </summary>
        private void Bind()
        {
            #region 检验作业表有效性
            QueryParameters query = new QueryParameters();
            query.Add("TableID", Request.QueryString["ID"], QueryParameters.OperatorType.Equal);
            List<Bu_BatchRec> lsBatchRec = new BaseBusinessLogic<Bu_BatchRec>(Globals.CurrentConnStringName).GetEntitys(query);
            if (lsBatchRec == null || lsBatchRec.Count != 1)
            {
                ScriptHelper.Window.AlertClose("找不到作业表对应的回执！", false);
                return;
            }
            theTable = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).GetAuditTable(Request.QueryString["ID"]);
            if (theTable == null)
            {
                ScriptHelper.Window.AlertClose("找不到符合条件的作业表！", false);
                return;
            }
            #endregion

            this.Title = "审核作业单号【" + theTable.Code + "】";//标题设置为作业表编号
            hidBuStatus.Value = theTable.BuStatus;
            _BuStatus = theTable.BuStatus;
            _Code = theTable.Code;
            _BatchNo = theTable.BatchNo.ToString();
            _SwfFilePath = Globals.Home + "Reports/" + theTable.BatchNo + "/" + theTable.Code + ".swf";

            btnPrint.Enabled = true;

            #region 签收按钮
            btnViewReceive.Attributes.Add("onclick", "javascript:doReceive('" + lsBatchRec[0].ID + "');return false;");
            btnReceive.Attributes.Add("onclick", "javascript:return doReceive('" + lsBatchRec[0].ID + "');");
            
            #endregion

            #region 转义代建单位
            if (theTable.DOwners == null || theTable.DOwners.Count == 0)
            {
                theTable.DOwnerName = "";
            }
            else
            {
                string downerStr = "";
                foreach (Bu_AuditTable_DOwner item in theTable.DOwners)
                {
                    if (downerStr != "") { downerStr += "<br/>"; }
                    downerStr += item.CompanyName;
                }
                theTable.DOwnerName = downerStr;
            }
            #endregion

            #region 绑定各项数据
            //本期本合同同时申请
            rptCurOther.DataSource = theTable.CurOther_C;
            rptCurOther.DataBind();
            //其他分项目（非A表时绑定）
            if (theTable.TableType != "A")
            {
                rptOtherProject.DataSource = theTable.CurOther_Split;
                rptOtherProject.DataBind();
            }
            //本合同未拨付
            rptTAmount_C_NA.DataSource = theTable.PastTime_C_NA;
            rptTAmount_C_NA.DataBind();
            //本期本项目同时申请
            rptCurOtherP.DataSource = theTable.CurOther_P;
            rptCurOtherP.DataBind();
            //本项目未拨付
            rptTAmount_P_NA.DataSource = theTable.PastTime_P_NA;
            rptTAmount_P_NA.DataBind();
            #region 投资计划
            yearCount = theTable.YearPlans.Count;
            for (int i = 0; i < yearCount; i++)
            {
                if (yearString != "") { yearString += "+"; }
                yearString += "P" + (i + 1).ToString();
            }
            rptYearPlan.DataSource = theTable.YearPlans;
            rptYearPlan.DataBind();
            #endregion

            #region 单选控件值

            rblPD1.SelectedValue = theTable.AuditCase.IsPD1 ? "1" : "0";
            rblPD2.SelectedValue = theTable.AuditCase.IsPD2 ? "1" : "0";
            rblPD3.SelectedValue = theTable.AuditCase.IsPD3 ? "1" : "0";
            rblPD4.SelectedValue = theTable.AuditCase.IsPD4 ? "1" : "0";
            rblPD5.SelectedValue = theTable.AuditCase.IsPD5 ? "1" : "0";
            rblPD6.SelectedValue = theTable.AuditCase.IsPD6 ? "1" : "0";
            rblPD7.SelectedValue = theTable.AuditCase.IsPD7 ? "1" : "0";
            rblPD8.SelectedValue = theTable.AuditCase.IsPD8 ? "1" : "0";
            rblPD9.SelectedValue = theTable.AuditCase.IsPD9 ? "1" : "0";
            rblPD10.SelectedValue = theTable.AuditCase.IsPD10 ? "1" : "0";

            rblCD1.SelectedValue = theTable.AuditCase.IsCD1 ? "1" : "0";
            rblCD2.SelectedValue = theTable.AuditCase.IsCD2 ? "1" : "0";
            rblCD3.SelectedValue = theTable.AuditCase.IsCD3 ? "1" : "0";
            rblCD4.SelectedValue = theTable.AuditCase.IsCD4 ? "1" : "0";
            rblCD5.SelectedValue = theTable.AuditCase.IsCD5 ? "1" : "0";
            rblCD6.SelectedValue = theTable.AuditCase.IsCD6 ? "1" : "0";
            rblCD7.SelectedValue = theTable.AuditCase.IsCD7 ? "1" : "0";
            rblCD8.SelectedValue = theTable.AuditCase.IsCD8 ? "1" : "0";
            rblCD9.SelectedValue = theTable.AuditCase.IsCD9 ? "1" : "0";

            rblZD1.SelectedValue = theTable.AuditCase.IsZD1 ? "1" : "0";
            rblZD2.SelectedValue = theTable.AuditCase.IsZD2 ? "1" : "0";
            rblZD3.SelectedValue = theTable.AuditCase.IsZD3 ? "1" : "0";
            rblZD4.SelectedValue = theTable.AuditCase.IsZD4 ? "1" : "0";

            #endregion

            #region 意见
            txtCD.Text = theTable.AuditCase.CD;
            txtCDOpinion.Text = theTable.AuditCase.CDOpinion;
            txtForCPriceOpinion.Text = theTable.AuditCase.ForCPriceOpinion;
            txtForLoanOpinion.Text = theTable.AuditCase.ForLoanOpinion;
            txtForPlanOpinion.Text = theTable.AuditCase.ForPlanOpinion;
            txtForPPriceOpinion.Text = theTable.AuditCase.ForPPriceOpinion;
            txtForProgress.Text = theTable.AuditCase.ForProgress;
            txtForProgressOpinion.Text = theTable.AuditCase.ForProgressOpinion;
            txtPD1.Text = theTable.AuditCase.PD1;
            txtPD1Opinion.Text = theTable.AuditCase.PD1Opinion;
            txtPD2.Text = theTable.AuditCase.PD2;
            txtPD2Opinion.Text = theTable.AuditCase.PD2Opinion;
            //txtZD.Text = theTable.AuditCase.ZD;
            txtZDOpinion.Text = theTable.AuditCase.ZDOpinion;
            #endregion
            ////如果是首次申请，则需要审核项目十项完整性，否则不需要
            //SetPDVisible(false);
            //if (theTable.SortNo == 1)
            //{
            //    SetPDVisible(true);
            //}
            ////如果已输出，不能再填写已经
            //if (theTable.BuStatus == ((int)EnumItem.AuditTableStatus.Output).ToString())
            //{
            //    SetOpinionReadOnly(true);
            //}


            #endregion

            if (!lsBatchRec[0].IsSend)//如果还未派单
            {
                lblInfo.Text = "批次管理员未对当前作业表的进行派单，不能进行操作！";
                btnPrint.Enabled = false;
            }
            else
            {
                WFApply.Tracker ITrack = new WFApply.Tracker();
                bool isCanTransact = ITrack.IsCanTransact(UserLoginer.LoginUser.ID, ((int)EnumItem.WFBill.AuditTable).ToString(), theTable.ID);
                
                #region 根据作业表业务状态设置有效性
                switch ((EnumItem.AuditTableStatus)int.Parse(theTable.BuStatus))
                {
                    case EnumItem.AuditTableStatus.NoRec://待签收
                        //未签收，当前用户必须是派单的人才可以签收
                        if (lsBatchRec[0].ToUserID == UserLoginer.LoginUser.ID)
                        {
                            lblInfo.Text = "请先进行执行作业表签收，然后开始审核作业表！";
                            btnReceive.Enabled = true;
                            //添加自动弹出签收
                            //Page.ClientScript.RegisterStartupScript(typeof(string), "receive", "document.getElementById('" + btnReceive.ClientID + "').click();", true);
                        }
                        else
                        {
                            lblInfo.Text = "对不起，你不是当前作业表的签收人，不能进行签收！";
                        }
                        numAmount_DocRec.Text = string.Format("{0:N}", theTable.Amount_DocRec);//申请金额
                        numCurAmount.Text = string.Format("{0:N}", theTable.Amount_F);//审核金额     
                        numAmount_C.Text = string.Format("{0:N}", theTable.Amount_C);//合同总价
                        numTAmount_C_A.Text = string.Format("{0:N}", theTable.TAmount_C_A_F);//前期该合同项下的累计拨款金额
                        btnPrint.Enabled = false;
                        break;
                    case EnumItem.AuditTableStatus.FAppr://初审
                        btnViewReceive.Enabled = true;
                        //如果当前员工是初审员，则可以修改数据
                        if (isCanTransact)
                        {
                            lblInfo.Text = "请对当前作业表进行审核工作！";
                            isEnabled = true;
                            SetAmountReadOnly(false);
                            SetOpinionReadOnly(false);
                            btnSave.Enabled = true;
                            //如果已经输入过，则显示输入过的值，否则显示0
                            numAmount_DocRec.Text = theTable.IsInputAmount_DocRec_F ? string.Format("{0:N}", theTable.Amount_DocRec_F) : "0";//审核员输入的申请金额
                            numAmount_DocRec.Attributes.Add("onchange", "javascript:confirmDocRec('" + theTable.Amount_DocRec.ToString("0.00") + "','0');Compute1();");
                            numCurAmount.Text = theTable.IsInputAmount_F ? string.Format("{0:N}", theTable.Amount_F) : "0";//审核金额
                            numCurAmount.Attributes.Add("onchange", "javascript:confirmAmount('" + theTable.Amount_DocRec.ToString("0.00") + "','0');Compute8();");
                            numAmount_C.Text = theTable.IsInputAmount_C_F ? string.Format("{0:N}", theTable.Amount_C_F) : "0";//合同总价
                            numAmount_C.Attributes.Add("onchange", "javascript:confirmContract('" + theTable.Amount_C.ToString("0.00") + "','0');Compute2();");
                            numTAmount_C_A.Text = theTable.IsInputTAmount_C_A_F ? string.Format("{0:N}", theTable.TAmount_C_A_F) : "0";//前期该合同项下的累计拨款金额
                            numTAmount_C_A.Attributes.Add("onchange", "javascript:Compute3();");
                        }
                        else
                        {
                            lblInfo.Text = "对不起，你不是当前作业表的审核员，不能进行操作！";
                            numAmount_DocRec.Text = string.Format("{0:N}", theTable.Amount_DocRec_F);//审核员输入的申请金额
                            numCurAmount.Text = string.Format("{0:N}", theTable.Amount_F);//审核金额
                            numAmount_C.Text = string.Format("{0:N}", theTable.Amount_C_F);//合同总价
                            numTAmount_C_A.Text = string.Format("{0:N}", theTable.TAmount_C_A_F);//前期该合同项下的累计拨款金额
                        }
                        break;
                    case EnumItem.AuditTableStatus.SAppr://复核
                        btnViewReceive.Enabled = true;
                        //如果当前员工是初审员，则可以修改数据
                        if (isCanTransact)
                        {
                            lblInfo.Text = "请对当前作业表进行复核工作！";
                            isEnabled = true;
                            SetAmountReadOnly(false);
                            SetOpinionReadOnly(false);
                            btnSave.Enabled = true;
                            //如果已经输入过，则显示输入过的值，否则显示0
                            numAmount_DocRec.Text = theTable.IsInputAmount_DocRec_S ? string.Format("{0:N}", theTable.Amount_DocRec_S) : "0";//复核员输入的申请金额
                            numAmount_DocRec.Attributes.Add("onchange", "javascript:confirmDocRec('" + theTable.Amount_DocRec_F.ToString("0.00") + "','1');Compute1();");
                            numCurAmount.Text = theTable.IsInputAmount_S ? string.Format("{0:N}", theTable.Amount_S) : "0";//复核员输入的审核金额
                            numCurAmount.Attributes.Add("onchange", "javascript:confirmAmount('" + theTable.Amount_F.ToString("0.00") + "','1');Compute8();");
                            numAmount_C.Text = theTable.IsInputAmount_C_S ? string.Format("{0:N}", theTable.Amount_C_S) : "0";//合同总价
                            numAmount_C.Attributes.Add("onchange", "javascript:confirmContract('" + theTable.Amount_C_F.ToString("0.00") + "','1');Compute2();");
                            numTAmount_C_A.Text = theTable.IsInputTAmount_C_A_F ? string.Format("{0:N}", theTable.TAmount_C_A_F) : "0";//前期该合同项下的累计拨款金额
                            numTAmount_C_A.Attributes.Add("onchange", "javascript:confirmTotalBFAmount('" + theTable.TAmount_C_A_F.ToString("0.00") + "');Compute3();");
                        }
                        else
                        {
                            lblInfo.Text = "对不起，你不是当前作业表的复核员，不能进行操作！";
                            numAmount_DocRec.Text = string.Format("{0:N}", theTable.Amount_DocRec_S);//审核员输入的申请金额
                            numCurAmount.Text = string.Format("{0:N}", theTable.Amount_S);//审核金额
                            numAmount_C.Text = string.Format("{0:N}", theTable.Amount_C_S);//合同总价
                            numTAmount_C_A.Text = string.Format("{0:N}", theTable.TAmount_C_A_S);//前期该合同项下的累计拨款金额
                        }
                        break;
                    case EnumItem.AuditTableStatus.Lock://锁定
                        lblInfo.Text = "当前作业表已锁定！";
                        btnViewReceive.Enabled = true;
                        numAmount_DocRec.Text = string.Format("{0:N}", theTable.Amount_DocRec_S);//审核员输入的申请金额
                        numCurAmount.Text = string.Format("{0:N}", theTable.Amount_S);//审核金额
                        numAmount_C.Text = string.Format("{0:N}", theTable.Amount_C_S);//合同总价
                        numTAmount_C_A.Text = string.Format("{0:N}", theTable.TAmount_C_A_S);//前期该合同项下的累计拨款金额
                        if (isCanTransact)
                        {
                            btnSave.Enabled = true;
                            isEnabled = true;
                            SetOpinionReadOnly(false);
                        }
                        break;
                    case EnumItem.AuditTableStatus.Output://输出
                        lblInfo.Text = "当前作业表已输出！";
                        btnViewReceive.Enabled = true;
                        numAmount_DocRec.Text = string.Format("{0:N}", theTable.Amount_DocRec_S);//审核员输入的申请金额
                        numCurAmount.Text = string.Format("{0:N}", theTable.Amount_S);//审核金额
                        numAmount_C.Text = string.Format("{0:N}", theTable.Amount_C_S);//合同总价
                        numTAmount_C_A.Text = string.Format("{0:N}", theTable.TAmount_C_A_S);//前期该合同项下的累计拨款金额
                        if (isCanTransact)
                        {
                            btnSave.Enabled = true;
                            isEnabled = true;
                            SetOpinionReadOnly(false);
                        }
                        break;
                    default:
                        break;
                }
                #endregion

                if (!isCanTransact && (EnumItem.AuditTableStatus)int.Parse(theTable.BuStatus) != EnumItem.AuditTableStatus.NoRec)
                {
                    if (UserLoginer.LoginUser.IsAdmin || (UserLoginer.LoginUser.Roles != null && UserLoginer.LoginUser.Roles.Contains("Administrators")))
                    {
                        lblInfo.Text = "您是系统管理员角色，请谨慎操作！";
                        isEnabled = true;
                        SetOpinionReadOnly(false);
                        SetAmountReadOnly(false);
                        btnSave.Enabled = true;
                        numCurAmount.Attributes.Add("onchange", "javascript:doBackAT('" + theTable.Amount_S.ToString() + "',this.value);Compute8();");
                        numAmount_DocRec.Attributes.Add("onchange", "javascript:Compute1()");
                        numAmount_C.Attributes.Add("onchange", "javascript:Compute2();");
                        numTAmount_C_A.Attributes.Add("onchange", "javascript:Compute3();");
                    }
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Save())
                {
                    ScriptHelper.Window.Alert("保存成功！", "outputExcel();unlocking();");
                    BindControl();
                    Bind();
                    BindWF();
                }
                else
                {
                    ScriptHelper.Window.Alert("保存失败！", "unlocking();");
                }
            }
            catch (Exception ex)
            {
                ScriptHelper.Window.Alert("保存失败！" + ex.Message, "unlocking();");
            }
        }

        private bool Save()
        {
            bool bSave = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).SaveAuditTable(
               Request.QueryString["ID"], hidBuStatus.Value, Convert.ToDecimal(numAmount_DocRec.Text), Convert.ToDecimal(numCurAmount.Text), Convert.ToDecimal(numTAmount_C_A.Text), Convert.ToDecimal(numAmount_C.Text),
            rblPD1.SelectedValue == "1", rblPD2.SelectedValue == "1", rblPD3.SelectedValue == "1", rblPD4.SelectedValue == "1", rblPD5.SelectedValue == "1", rblPD6.SelectedValue == "1", rblPD7.SelectedValue == "1", rblPD8.SelectedValue == "1", rblPD9.SelectedValue == "1", rblPD10.SelectedValue == "1",
            txtPD1.Text, txtPD1Opinion.Text, txtPD2.Text, txtPD2Opinion.Text,
            rblCD1.SelectedValue == "1", rblCD2.SelectedValue == "1", rblCD3.SelectedValue == "1", rblCD4.SelectedValue == "1", rblCD5.SelectedValue == "1", rblCD6.SelectedValue == "1", rblCD7.SelectedValue == "1", rblCD8.SelectedValue == "1", rblCD9.SelectedValue == "1",
            txtCD.Text, txtCDOpinion.Text,
            rblZD1.SelectedValue == "1", rblZD2.SelectedValue == "1", rblZD3.SelectedValue == "1", rblZD4.SelectedValue == "1",
                //txtZD.Text, txtZDOpinion.Text,
            "", txtZDOpinion.Text,
            txtForPPriceOpinion.Text, txtForPlanOpinion.Text,
            txtForLoanOpinion.Text, txtForCPriceOpinion.Text,
            txtForProgress.Text, txtForProgressOpinion.Text);
            return bSave;
        }
    }
}